package com.darren.euc.dao.impl;


import java.math.BigInteger;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.darren.euc.dao.OrderDao;
import com.darren.euc.entity.Order;


@Repository
public class OrderDaoImpl extends BaseDaoImpl<Order, Integer> implements OrderDao {
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Order> getAll() {
		Session session = sessionFactory.getCurrentSession();	
		List<Order> orders = session.createQuery("from Order").list();
		return orders;
	}

	
	public BigInteger getCurrentDayCount(Integer orderId){
		Session session = sessionFactory.getCurrentSession();	
		Query query  = session.createSQLQuery(" select count(1) from euc_orders where datediff(now(),create_time) = 0 and id <= ? ; ");
		query.setParameter(0, orderId);
		BigInteger count = (BigInteger) query.uniqueResult();
		return  count;
	}
}